package com.own.business.question.common.constant;

import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.em.DefaultReplyEnvironment;
import com.own.business.question.common.em.NotFoundReplyEnvironment;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * ConstantReplyEnvironment
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/5/14 15:37
 * @since 4.0.0
 */
@Slf4j
public final class ConstantReplyEnvironment {

    private final static Map<Integer, ReplyEnvironment> MAP = new HashMap<>();

    static {
        put(DefaultReplyEnvironment.values());
    }

    public static ReplyEnvironment get(int type) {
        return MAP.getOrDefault(type, NotFoundReplyEnvironment.NONULL);
    }

    public static void put(int type, ReplyEnvironment environment) {
        if (MAP.containsKey(type)) {
            log.error("{}的类型type:{},已经存在", environment.title(), environment.type());
            return;
        }
        MAP.put(type, environment);
    }

    public static void put(ReplyEnvironment... array) {
        for (var item : array) {
            put(item.type(), item);
        }
    }

}
